# -*- coding: utf-8 -*-

"""
数据模型定义
"""

from typing import Optional, Dict, Any
from dataclasses import dataclass, field
from decimal import Decimal


@dataclass
class OrderFee:
    """订单费用信息"""
    actual_amount: Optional[Decimal] = None     # 实际支付金额
    total_amount: Optional[Decimal] = None      # 总金额
    toll_fee: Optional[Decimal] = None          # 过路费
    handling_fee: Optional[Decimal] = None      # 手续费
    waiting_fee: Optional[Decimal] = None       # 等待费
    parking_fee: Optional[Decimal] = None       # 停车费


@dataclass
class Order:
    """订单信息"""
    id: int                                                    # 订单ID
    order_no: str                                             # 本地订单号
    platform_order_no: Optional[str] = None                  # 平台订单号
    jd_store_id: Optional[str] = None                         # 京东门店ID
    carrier_merchant_id: Optional[str] = 'HBT_JZD'           # 配送商商户ID
    rider_id: Optional[int] = None                            # 骑手ID
    rider_name: Optional[str] = None                          # 骑手姓名
    rider_phone: Optional[str] = None                         # 骑手手机号
    rider_lng: Optional[float] = None                         # 骑手经度
    rider_lat: Optional[float] = None                         # 骑手纬度
    fee: Optional[OrderFee] = None                           # 费用信息


@dataclass
class CallbackResult:
    """回调结果"""
    success: bool                                             # 是否成功
    message: str                                              # 消息
    data: Optional[Dict[str, Any]] = None                    # 响应数据
    deduplicated: bool = False                               # 是否被防重复跳过


@dataclass
class DnsResult:
    """DNS解析结果"""
    host: str                                                 # 主机名
    ip: str                                                   # IP地址
    success: bool                                             # 是否成功


@dataclass
class PortResult:
    """端口连通性结果"""
    host: str                                                 # 主机名
    port: int                                                 # 端口号
    success: bool                                             # 是否成功
    error: Optional[str] = None                              # 错误信息


@dataclass
class HttpResult:
    """HTTP请求结果"""
    success: bool                                             # 是否成功
    http_code: int                                            # HTTP状态码
    error: Optional[str] = None                              # 错误信息


@dataclass
class ConnectivityResult:
    """连通性测试结果"""
    dns: DnsResult                                            # DNS解析结果
    port: PortResult                                          # 端口连通性结果
    http: HttpResult                                          # HTTP请求结果


@dataclass
class SDKConfig:
    """SDK配置"""
    developer_id: str                                         # 开发者ID
    secret: str                                               # 签名密钥
    environment: str = 'test'                                 # 环境: test, sandbox, prod
    redis_config: Optional[Dict[str, Any]] = None           # Redis配置
    enable_log: bool = True                                   # 启用日志
    user_agent: str = 'JingdongCallbackSDK-Python/1.0.0'    # 用户代理
    timeout: int = 120                                        # 请求超时时间（秒）
    max_retry: int = 3                                        # 最大重试次数
